package com.problem.leetcode;

/**
 * 注释中的解法1虽然高效，但是进行了两次比较，还是有继续优化的空间的
 */
public class Problem485 {
//    public int findMaxConsecutiveOnes(int[] nums) {
//        int oneCount = 0, currentCount = 0;
//
//        for (int index = 0; index < nums.length; index++) {
//            currentCount = nums[index] == 1 ? ++currentCount : 0;
//            oneCount = currentCount > oneCount ? currentCount : oneCount;
//        }
//        return oneCount;
//    }

    public int findMaxConsecutiveOnes(int[] nums) {
        int oneCount = 0, currentCount = 0;

        for (int index = 0; index < nums.length; index++) {
            if (nums[index] != 1) {
                currentCount = 0;
            } else {
                ++currentCount;
                oneCount = currentCount > oneCount ? currentCount : oneCount;
            }
        }
        return oneCount;
    }

}
